<template>
	<view class="">
		<view class="jui_flex jui_flex_justify_between top jui_bg_fff" style="padding: 20rpx 120rpx;position: fixed;top: 80rpx;width: 100%;z-index: 1000;">
			<view class="jui_flex_col_center" v-for="(item,index) in tab" :key="index" @tap="chooseTab(item,index)">
				<view class="">
					{{item.text}}
				</view>
				<view class="jui_mar_t12" :class="tabIndex==index?'on':''">

				</view>
			</view>
		</view>
		<view class="jui_h100">
			
		</view>
		<view class="jui_h20">
			
		</view>
		<view class="jui_mar_2432">
			<scroll-view class="scroll-view_H " scroll-y="true">
				<view class=" scroll-view-item_H jui_mar_b20   jui_bg_fff " style="padding: 22upx 50upx;"  v-for="(row,i) in couponList" :key="i">
					<view class="jui_bor_bottom jui_pad_b20">
						{{row.name}}
					</view>
					<view class="flex justify-between jui_flex_items_center jui_mar_t20 jui_pad_t20">
						<view class="jui_flex_col_center">
							<view class="jui_fc_999">
								剩余收益
							</view>
							<view class="jui_mar_t16">
								{{row.no_award_quota}}U
							</view>
						</view>
						<view class="jui_flex_col_center">
							<view class="jui_fc_999">
								剩余时间
							</view>
							<view class="jui_mar_t16">
								{{row.valid_period}}h
							</view>
						</view>
						<view class="">
							<view class="zhuanzeng" @tap="zhuangzeng(row)" v-if="tabIndex == 0">
								转增
							</view>
							<view class="use jui_mar_t16" @tap="use(row)" v-if="tabIndex == 0">
								立即使用
							</view>
						</view>
					</view>
					
				</view>
				<!-- 空白页 -->
				<shopro-empty v-if="!couponList.length " :emptyData="emptyData"></shopro-empty>
			</scroll-view>
		</view>
		<uni-popup ref="popup" type="dialog">
			<uni-popup-dialog type="input" message="成功消息" :duration="2000" :before-close="true" @close="close"
				@confirm="confirm" mode="input" title="转赠"  placeholder="请输入对方手机号"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue'
	import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
	export default {
		components: {
			uniPopup,
			uniPopupMessage,
			uniPopupDialog
		},
		data() {
			return {
				emptyData: {
					img: '/static/imgs/home/empty_goods.png',
					tip: '暂无数据'
				},
				tab: [{
						text: '未使用'
					},
					{
						text: '已使用'
					},
				],
				tabIndex: 0,
				couponList: [],
				page:1,
				size:20,
				status:0,
				hasMore:false,
				FromToken:'',
				id:''
			}
		},
		onLoad() {
			// this.couponlist()
		},
		onShow() {
			this.getFromToken();
		},
		onReachBottom(){
			if(this.hasMore){
				this.page ++ ;
				this.couponlist()
			}
		},
		methods: {
			close(done) {
				done()
			},
			confirm(done, value) {
				// 输入框的值
				console.log(value)
				if (!value) {
					this.$msg('请输入对方手机号码')
					return false;
					done()
				} else {
					let data = {
						id: this.id,
						mobile: value
					}
					this.$api.give(data).then(res => {
						if (res.code == 1) {
							this.$msg(res.msg);
							setTimeout(()=>{
								uni.navigateBack()
							},1000)
							done()
						}
					});
				}
			
				done()
			},
			zhuangzeng(row){
				console.log(row)
				this.id = row.id;
				this.$refs.popup.open()
			},
			use(row){
				let data = {
					FromToken:this.FromToken,
					id:row.id 
				}
				this.$api.use(data).then(res => {
					if(res.code == 1){
						this.$msg(res.msg);
						setTimeout(()=>{
							uni.navigateBack()
						},1000)
					}
				});
			},
			getFromToken() {
				this.$api.getFromToken({data:1}).then(res => {
					if (res.code == 1) {
						this.FromToken = res.FromToken;
						this.couponlist()
					}
				});
			},
			couponlist(){
				let data = {
					FromToken:this.FromToken,
					status:this.status
				}
				this.$api.getMyCard(data).then(res => {
					this.couponList = res.data.data;
					this.id  = this.couponList[0].id,
					console.log(this.couponList);
				
				});
			},
			chooseTab(item, index) {
				this.page = 1,
				this.tabIndex = index;
				this.status = index
				this.couponList = [];
				this.couponlist()
			},
			goHome(){
				uni.switchTab({
					url:'/pages/home/home'
				})
			},
			detail() {
				uni.navigateTo({
					url: '/pages/user/hotelOrders/hotelOrderDetail'
				})
			},
		}
	}
</script>

<style lang="scss">
	
	/*  #ifndef H5 */
	.top {
		top:0rpx !important;
	}
	/* #endif */
	.coupon {
		background: url(/static/imgs/home/card.png) 0 0 / 100% 100% no-repeat;
	}
	.couponbg {
		background: url(/static/imgs/home/card.png) 0 0 / 100% 100% no-repeat;
	}
	.on {
		width: 30rpx;
		height: 10rpx;
		background-color:$zhuse;
		border-radius: 10rpx;
	}
	.zhuanzeng {
		width: 140rpx;
		height: 56rpx;
		border-radius: 8rpx;
		border: 2rpx solid $zhuse;
		text-align: center;
		line-height: 56rpx;
		color: $zhuse;
	}
	.use {
		width: 140rpx;
		height: 56rpx;
		background:$zhuse;
		border-radius: 8rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 56rpx;
	}
</style>
